package it.uni.bo.monitoring.protocol.unmarshaller;

import it.uni.bo.monitoring.mapping.hibernate.Application;
import it.uni.bo.monitoring.mapping.hibernate.Client;
import it.uni.bo.monitoring.mapping.hibernate.Ws;
import it.uni.bo.monitoring.mapping.hibernate.WsOperation;
import it.uni.bo.monitoring.protocol.server.DataObject;

import java.nio.ByteBuffer;
import java.util.Set;

import org.apache.log4j.Logger;


public class EventInfo {

	private byte[] idE;
	private long idA=-1;
	private int size;
	private String appUrl;
	private String namespace;
	private long idWs=-1;
	private long idWso=-1;
	private String operationName;
	private long seqNumber;
	private long idU=-1;
	private String username;
	private char direction;
	private String password;
	private long timestamp=-1;
	private String session;
	private long idSla=-1;
	private boolean goodUse;
	private DataObject rdo;
	private String failDesc;
	private Logger l= Logger.getLogger(this.getClass());;
	private Set<EventParameterInfo> setEventParameters;
	
	public EventInfo(DataObject rdo) {
		setDataObject(rdo);
	}
	
	public void setIdE(byte[] idE) {
		this.idE = idE;
	}
	public byte[] getIdE() {
		return idE;
	}

	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	
	public void setSeqNumber(long seqNumber) {
		this.seqNumber = seqNumber;
	}
	public long getSeqNumber() {
		return seqNumber;
	}
	
	public void setDirection(char direction) {
		this.direction = direction;
	}
	public char getDirection() {
		return direction;
	}
	
	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}
	public long getTimestamp() {
		return timestamp;
	}
	
	public void setSession(String session) {
		this.session = session;
	}
	public String getSession() {
		return session;
	}
	
	public void setIdSla(Long idSla) {
		this.idSla=idSla;
	}
	public long getIdSla() {
		return idSla;
	}
	
	public void setApplication(Application application) {
		this.idA=application.getIdA();
	}
	public long getIdA() {
		return idA;
	}
	public String getAppUrl() {
		return appUrl;
	}
	public void setAppUrl(String appUrl){
		this.appUrl=appUrl;
	}
	
	
	public void setClient(Client client) {
		this.idU=client.getIdU();
	}
	public long getIdU() {
		return idU;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username=username;
	}
	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password){
		this.password=password;
	}
	
	
	public void setWs(Ws ws) {
		this.idWs=ws.getIdWs();
	}
	public Long getIdWs() {
		return idWs;
	}
	public String getNamespace() {
		return namespace;
	}
	public void setNamespace(String namespace){
		this.namespace=namespace;
	}

	
	public void setWsOperation(WsOperation wsOperation) {
		this.idWso=wsOperation.getIdWso();
	}
	public Long getIdWso() {
		return idWso;
	}
	public void setOperationName(String operationName){
		this.operationName=operationName;
	}
	public String getOperationName() {
		return operationName;
	}
	
	
	public void setGoodUse(boolean goodUse) {
		this.goodUse = goodUse;
	}
	public boolean isGoodUse() {
		if(this.namespace.equalsIgnoreCase("http://www.airline.com/"))
			goodUse=true;
		else
			goodUse=false;
		return goodUse;
	}
	public void setDataObject(DataObject rdo) {
		this.rdo=rdo;
		setIdE(rdo.getKey());
		setDirection(Character.forDigit(rdo.getDirection() & 0xFF, 2));
		setSize(rdo.getSize());
		setNamespace(new String(rdo.getWSNamespace()));
		setAppUrl(new String(rdo.getAppLURL()));
		setOperationName(new String(rdo.getOperation()));
		setPassword(new String(rdo.getPassword()));
		setSession(new String(rdo.getSession()));
		setUsername(new String(rdo.getUsername()));
		try{
			setSeqNumber(Long.valueOf(new String(rdo.getSeqNumber())));
		}catch(NumberFormatException e){
			l.error("ERRORE CONVERSIONE LONG SEQ_NUMBER");
		}
		try{
			setTimestamp(Long.valueOf(new String(rdo.getTimestamp())));
		}catch(NumberFormatException e){
			//l.error("ERRORE CONVERSIONE LONG TIMESTAMP");
			setTimestamp(ByteBuffer.wrap(rdo.getTimestamp()).getLong());
		}
		
	}
	
	public String getFailDesc(){
		return failDesc;
	}
	public void setFailDesc(String failDesc) {
		this.failDesc=failDesc;
	}
	public DataObject getDataObject(){
		return this.rdo;
	}

	public void setEventParameters(Set<EventParameterInfo> setEventParameters) {
		this.setEventParameters=setEventParameters;
	}
	
	public Set<EventParameterInfo> getEventParameterInfo(){
		return this.setEventParameters;
	}

}
